package com.dmooo.ymx.malladapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.dmooo.ymx.R;
import com.dmooo.ymx.config.Constants;
import com.dmooo.ymx.mall.MallGoodsDetailsActivity;
import com.dmooo.ymx.mall.MallGoodsDetailsActivity1;
import com.dmooo.ymx.mall.ShopMallActivity1;
import com.dmooo.ymx.mallbean.ShopMallGoodsBean;
import com.dmooo.ymx.userupdate.UpdateGroupActivity;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.List;

public class ShopMallGoodsRecyclerAdapter1 extends CommonAdapter<ShopMallGoodsBean> {
    Drawable drawable;
    private OnDeleteClickLister mDeleteClickListener;
    public ShopMallGoodsRecyclerAdapter1(Context context, int layoutId, List<ShopMallGoodsBean> datas) {
        super(context, layoutId, datas);
    }

    @Override
    protected void convert(ViewHolder holder, ShopMallGoodsBean item, int position) {
        //设置图片
        ImageView imageView = holder.getView(R.id.image);
        Log.d("dfawef",item.img);
        Glide.with(mContext).load(item.img.contains("http")?item.img: Constants.APP_IP+item.img).error(R.mipmap.logo_app).dontAnimate().into(imageView);
        ((TextView) holder.getView(R.id.title_child)).setText(item.goods_name);

        holder.setText(R.id.tx2, item.price+"积分");
        holder.setText(R.id.tx2_2 ,item.old_price);
        TextView tx2_2 = holder.getView(R.id.tx2_3);
        tx2_2.setText("已兑" + item.sales_volume);
//        holder.setText(R.id.title_child2,"预估赚:"+item.commission);
        holder.setText(R.id.title_child2,"浏览量:"+item.clicknum);
        holder.setText(R.id.tx5, "赠送积分:" + item.give_point);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putString("goods_id", item.goods_id);
                if(mContext instanceof UpdateGroupActivity){
                    bundle.putString("isVip","1");
                }
                Intent intent = new Intent(mContext, MallGoodsDetailsActivity.class);
                if(mContext instanceof ShopMallActivity1){
                    intent = new Intent(mContext, MallGoodsDetailsActivity1.class);
                }
                intent.putExtras(bundle);
                mContext.startActivity(intent);
            }
        });
        if(mContext instanceof UpdateGroupActivity){
            holder.getView(R.id.tx2_2).setVisibility(View.GONE);
            holder.getView(R.id.title_child2).setVisibility(View.GONE);
            holder.getView(R.id.txt_day).setVisibility(View.GONE);
//            holder.setText(R.id.txt_day,item.day_num+"天会员");
        }
    }
    public void setOnDeleteClickListener(OnDeleteClickLister listener) {
        this.mDeleteClickListener = listener;
    }

    public interface OnDeleteClickLister {
        void onDeleteClick(View view, int position);
    }
}
